package com.wxx.web.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

/**
 * 接口文档配置(可与yaml文件中knife4j配置替换)
 * "http://localhost:8120/api/doc.html#/home"(测试链接)
 *
 * @author <a href="https://gitee.com/you4189/you-generator">you</a>
 * @from <a href="https://gitee.com/you4189/you-generator">gitee</a>
 */
@Configuration
@EnableSwagger2WebMvc
@EnableKnife4j //API接口文档的开关
@ConditionalOnExpression("${knife4j.enable}") // 开启访问接口文档的权限
public class Knife4jConfig {

    @Bean
    public Docket defaultApi2(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(new ApiInfoBuilder()
                        .title("接口文档")
                        .contact(new Contact("you", "https://gitee.com/you4189", "wxx4189@126.com"))
                        .description("代码生成器后端接口测试文档")
                        .version("1.0")
                        .build())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.wxx.web.controller"))
                .paths(PathSelectors.any())
                .build();
    }

}
